import numpy as np

from PIL import Image
# b=114
# g=587
# r=299
# img = Image.open('down.jpg')
# pix = np.array(img)
# for i in range(100):
#     for j in range(100):
#         pix[i][j]=pix[0][0]/100
# print(pix[0][0])
# print (pix.shape)
# pix_gray = (r*pix[:,:,0]+g*pix[:,:,1]+b*pix[:,:,2])/500
# img_ = Image.fromarray(pix_gray)
# img_=img_.convert('L')
# img_.save('down.bmp')
# img_.show()

up = [[510, 92],
      [381, 398],
      [327, 330],
      [121, 312],
      [254, 173],
      [69, 140],
      [99, 62]]
up = np.mat(up)
# (u,v)
down = [[51, 138],
        [384, 37],
        [369, 125],
        [480, 289],
        [292, 285],
        [386, 440],
        [300, 481]]
down = np.mat(down)
A = []
# B0=np.zeros((6,1))
# B1=B0.copy()
for i in range(7):
    line = [1, down[i, 0], down[i, 1], down[i, 0] ** 2, down[i, 1] ** 2, down[i, 0] * down[i, 1]]
    A.append(line)
A = np.mat(A)
B0 = ((A.T * A).I * A.T) * up[:, 0]
B1 = ((A.T * A).I * A.T) * up[:, 1]
print(B0)
print(B1)

down=np.array(down)

for i in down:
    u = i[0]
    v = i[1]
    a = [1,u,v,u**2,v**2,u*v]
    x = a*B0
    y = a*B1
    print(x,y)

# fft_no_shift = np.abs(fft_pix) / 2000
# fft_no_shift=Image.fromarray(fft_no_shift)
# fft_no_shift.show()


